package com.qiaofang.applet.rest;

import com.qiaofang.applet.common.dto.DataRequest;
import com.qiaofang.applet.common.dto.DataResponse;
import com.qiaofang.applet.common.dto.PageDataRequest;
import com.qiaofang.applet.common.util.PageUtil;
import com.qiaofang.applet.service.member.service.AppointmentService;
import com.qiaofang.applet.service.member.service.dto.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.validation.Valid;
import java.util.List;

/**
 * @author daiyuxaing
 */
@Slf4j
@RestController
@RequestMapping("/api/web/appointment")
@Api(tags = "预约带看：预约带看模块")
public class AppointmentController {

    @Autowired
    AppointmentService appointmentService;

    private static RestTemplate restTemplate = new RestTemplate();

    @PostMapping("/getEmpList")
    @ApiOperation(value = "获取预约经纪人列表", notes = "获取预约经纪人列表")
    public DataResponse<List<AppointmentEmpListDto>> getEmpList(@RequestBody @Valid DataRequest<AppointmentEmpQueryDto> request) {
        return DataResponse.ok(appointmentService.getEmpList(request.getParam()));
    }

    @PostMapping("/submit")
    @ApiOperation(value = "提交预约申请", notes = "提交预约申请")
    public DataResponse<Object> submit(@RequestBody @Valid DataRequest<AppointmentSubmitDto> request) {
        appointmentService.submitAppointment(request.getParam());
        return DataResponse.ok();
    }

    @PostMapping("/getMyList")
    @ApiOperation(value = "我的预约列表", notes = "我的预约列表")
    public DataResponse<Page<MyAppointmentListDto>> getMyList(@RequestBody @Valid PageDataRequest<MyAppointmentQueryDto> request) {
        return DataResponse.ok(appointmentService.getMyAppointmentList(request.getParam(), PageUtil.getPageable(request)));
    }

    @PostMapping("/cancel")
    @ApiOperation(value = "取消预约", notes = "取消预约")
    public DataResponse<Object> cancel(@RequestBody @Valid DataRequest<AppointmentOpDto> request) {
        appointmentService.cancelAppointment(request.getParam().getId());
        return DataResponse.ok();
    }

    @PostMapping("/affirm")
    @ApiOperation(value = "确认已带看", notes = "确认已带看")
    public DataResponse<Object> affirm(@RequestBody @Valid DataRequest<AppointmentOpDto> request) {
        appointmentService.affirmAppointment(request.getParam());
        return DataResponse.ok();
    }
}
